package com.yunxi.controller.approve;

import com.github.pagehelper.PageInfo;
import com.yunxi.core.web.ApiResult;
import com.yunxi.core.web.CurrentUser;
import com.yunxi.core.web.LoginInfo;
import com.yunxi.core.web.ResponseUtil;
import com.yunxi.order.pojo.*;
import com.yunxi.order.service.OrderOemManagerDubboService;
import com.yunxi.vehicle.pojo.VehicleCertReqVO;
import com.yunxi.vehicle.pojo.VehicleCertRespVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "wholesale:orderAutitManager",description = "主机厂管理接口")
@RestController
@RequestMapping("/wholesale/orderAutitManager")
public class OrderApproveManagerController {
    @Autowired
    private OrderOemManagerDubboService orderOemManagerDubboService;


    @ApiOperation(value = "修改订单审核主数据查询")
    @GetMapping(value = "/queryOrderAutitInfoForPage")
    public ApiResult<OrderApproveRespVO> queryOrderAutitInfoForPage(@CurrentUser LoginInfo user, OrderApproveReqVO vo, int pageNum, int pageSize) {
        Object partnerVO = (Object) user.getPartner();
        if(partnerVO != null){
             //
            //表示当前用户是主机厂
            return ResponseUtil.fail(401,"当前用户不是主机厂用户，请使用主机厂用户登录！");
        }

        PageInfo<OrderApproveRespVO> resp = orderOemManagerDubboService.queryOrderApproveInfoForPage(vo, pageNum, pageSize);
        return ResponseUtil.ok(resp);
    }

    @ApiOperation(value = "修改订单审核主数据查询")
    @GetMapping(value = "/queryModifyOrderForPage")
    public ApiResult<OrderApproveRespVO> queryModifyOrderForPage(@CurrentUser LoginInfo user, ModifyOrderReqVO vo, int pageNum, int pageSize){
        Object partnerVO = (Object) user.getPartner();
        if(partnerVO != null){
            //
            //表示当前用户是主机厂
            return ResponseUtil.fail(401,"当前用户不是主机厂用户，请使用主机厂用户登录！");
        }

        PageInfo<ModifyOrderRespVO> resp = orderOemManagerDubboService.queryModifyOrderForPage(vo, pageNum, pageSize);
        return ResponseUtil.ok(resp);
    }

    @ApiOperation(value = "主机厂取消订单审核主数据查询")
    @GetMapping(value = "/queryCancelOrderAutitForPage")
    public ApiResult<OrderApproveCancelRespVO> queryCancelOrderAutitForPage(@CurrentUser LoginInfo user,OrderApproveCancelReqVO vo, int pageNum, int pageSize) {
        Object partnerVO = (Object) user.getPartner();
        if(partnerVO != null){
            //
            //表示当前用户是主机厂
            return ResponseUtil.fail(401,"当前用户不是主机厂用户，请使用主机厂用户登录！");
        }
        PageInfo<OrderApproveCancelRespVO> resp = orderOemManagerDubboService.queryCancelOrderApproveForPage(vo, pageNum, pageSize);
        return ResponseUtil.ok(resp);
    }

    @ApiOperation(value = "主机厂订单管理订单查询")
    @GetMapping(value = "/queryOrderApproveForPage")
    public ApiResult<OrderVehicleManagerDetailsRespVO> queryOrderApproveForPage(@CurrentUser LoginInfo user,OrderVehicleManagerDetailsReqVO vo, int pageNum, int pageSize) {
        Object partnerVO = (Object) user.getPartner();
        if(partnerVO != null){
            //
            //表示当前用户是主机厂
            return ResponseUtil.fail(401,"当前用户不是主机厂用户，请使用主机厂用户登录！");
        }

        PageInfo<OrderVehicleManagerDetailsRespVO> resp = orderOemManagerDubboService.queryOrderApproveForPage(vo, pageNum, pageSize);
        return ResponseUtil.ok(resp);
    }

    @ApiOperation(value = "订单导出")
    @GetMapping(value = "/orderExport")
    public ApiResult orderExport(OrderVehicleManagerDetailsReqVO vo) {
        vo.setOrderType(0);
        return orderOemManagerDubboService.orderExport(vo);
    }

    @ApiOperation(value = "主机厂订单管理审核通过/驳回")
    @PostMapping(value = "/setOrderCheckStatus")
    public ApiResult<Boolean> setOrderCheckStatus(@CurrentUser LoginInfo user,@RequestBody OrderPassReqVO vo){
        Object partnerVO = (Object) user.getPartner();
        if(partnerVO != null){
            //
            //表示当前用户是主机厂
            return ResponseUtil.fail(401,"当前用户不是主机厂用户，请使用主机厂用户登录！");
        }

        vo.setUserCode(user.getUserCode());

        boolean isSuccess = orderOemManagerDubboService.setOrderCheckStatus(vo);
        return ResponseUtil.ok(isSuccess);
    }

    @ApiOperation(value = "主机厂订单管理订单设置优先级")
    @PostMapping(value = "/setOrderLevel")
    public ApiResult<Boolean> setOrderLevel(@RequestBody  OrderSetLevelReqVO vo,@CurrentUser LoginInfo user){
        Object partnerVO = (Object) user.getPartner();
        if(partnerVO != null){
            //
            //表示当前用户是主机厂
            return ResponseUtil.fail(401,"当前用户不是主机厂用户，请使用主机厂用户登录！");
        }

        vo.setUserCode(user.getUserCode());
        boolean isSuccess = orderOemManagerDubboService.setOrderLevel(vo);
        return ResponseUtil.ok(isSuccess);
    }

    @ApiOperation(value = "主机厂订单管理明细查询")
    @GetMapping(value = "/queryOrderApproveDetails")
   public ApiResult<OrderApproveDetailsRespVO> queryOrderApproveDetails(OrderApproveDetailsReqVO vo,@CurrentUser LoginInfo user){
        Object partnerVO = (Object) user.getPartner();
        if(partnerVO != null){
            //
            //表示当前用户是主机厂
            return ResponseUtil.fail(401,"当前用户不是主机厂用户，请使用主机厂用户登录！");
        }

        OrderApproveDetailsRespVO resp = orderOemManagerDubboService.queryOrderApproveDetails(vo);
        return ResponseUtil.ok(resp);
   }

    @ApiOperation(value = "主机厂订单管理订单配车库存资源")
    @GetMapping(value = "/queryStockResource")
    public ApiResult<StockResourceRespVO> queryStockResource(@CurrentUser LoginInfo user,StockOrProductionLineResourceReqVO vo,int pageNum,int pageSize){
        Object partnerVO = (Object) user.getPartner();
        if(partnerVO != null){
            //
            //表示当前用户是主机厂
            return ResponseUtil.fail(401,"当前用户不是主机厂用户，请使用主机厂用户登录！");
        }


        PageInfo<StockResourceRespVO> resp = orderOemManagerDubboService.queryStockResource(vo,pageNum,pageSize);
        return ResponseUtil.ok(resp);
    }

    @ApiOperation(value = "主机厂订单管理订单配车产线资源")
    @GetMapping(value = "/queryProductionLineResource")
    public ApiResult<ProductionLineResourceRespVO> queryProductionLineResource(@CurrentUser LoginInfo user,StockOrProductionLineResourceReqVO vo,int pageNum,int pageSize){
        Object partnerVO = (Object) user.getPartner();
        if(partnerVO != null){
            //
            //表示当前用户是主机厂
            return ResponseUtil.fail(401,"当前用户不是主机厂用户，请使用主机厂用户登录！");
        }
        PageInfo<ProductionLineResourceRespVO> resp = orderOemManagerDubboService.queryProductionLineResource(vo,pageNum,pageSize);
        return ResponseUtil.ok(resp);
    }

    @ApiOperation(value = "主机厂大客户订单管理订单配车库存资源")
    @GetMapping(value = "/queryStockResourceByVehicleCode")
    public ApiResult<StockResourceRespVO> queryStockResourceByVehicleCode(@CurrentUser LoginInfo user,StockOrProductionLineResourceReqVO vo,int pageNum,int pageSize){
        Object partnerVO = (Object) user.getPartner();
        if(partnerVO != null){
            //
            //表示当前用户是主机厂
            return ResponseUtil.fail(401,"当前用户不是主机厂用户，请使用主机厂用户登录！");
        }

        PageInfo<StockResourceRespVO> resp = orderOemManagerDubboService.queryStockResourceByVehicleCode(vo,pageNum,pageSize);
        return ResponseUtil.ok(resp);
    }


    @ApiOperation(value = "主机厂大客户订单管理订单配车产线资源")
    @GetMapping(value = "/queryProductionLineResourceByVehicleCode")
    public ApiResult<ProductionLineResourceRespVO> pageProductionLineResourceByVehicleCode(@CurrentUser LoginInfo user,StockOrProductionLineResourceReqVO vo,int pageNum,int pageSize){
        Object partnerVO = (Object) user.getPartner();
        if(partnerVO != null){
            //
            //表示当前用户是主机厂
            return ResponseUtil.fail(401,"当前用户不是主机厂用户，请使用主机厂用户登录！");
        }
        PageInfo<ProductionLineResourceRespVO> resp = orderOemManagerDubboService.pageProductionLineResourceByVehicleCode(vo,pageNum,pageSize);
        return ResponseUtil.ok(resp);
    }

//    @ApiOperation(value = "主机厂订单管理订单配车更换")
//    @GetMapping(value = "/updateVinOfOrderVehicle")
//    public ApiResult<Boolean> updateVinOfOrderVehicle(StockOrProductionLineResourceReqVO vo){
//        boolean isSuccess = orderOemManagerDubboService.updateVinOfOrderVehicle(vo);
//        return ResponseUtil.ok(isSuccess);
//    }

    @ApiOperation(value = "主机厂合格证管理主数据查询")
    @GetMapping(value = "/queryVehicleCert")
    public ApiResult<VehicleCertRespVO> queryVehicleCert(@CurrentUser LoginInfo user,VehicleCertReqVO vo, int pageNum, int pageSize){
        Object partnerVO = (Object) user.getPartner();
        if(partnerVO != null){
            //
            //表示当前用户是主机厂
            return ResponseUtil.fail(401,"当前用户不是主机厂用户，请使用主机厂用户登录！");
        }

        PageInfo<VehicleCertRespVO> pageInfo = orderOemManagerDubboService.queryVehicleCert(vo,pageNum,pageSize);
        return ResponseUtil.ok(pageInfo);
    }

    @ApiOperation(value = "自动配车")
    @PostMapping(value = "/orderAutoMatchCar")
    public ApiResult<Boolean> orderAutoMatchCar(@CurrentUser LoginInfo user,@RequestBody OrderApproveAutoMatchCarReqVO vo){
        Object partnerVO = (Object) user.getPartner();
        if(partnerVO != null){
            //
            //表示当前用户是主机厂
            return ResponseUtil.fail(401,"当前用户不是主机厂用户，请使用主机厂用户登录！");
        }

        return orderOemManagerDubboService.orderAutoMatchCar(vo);
    }

    @ApiOperation(value = "手动配车")
    @PostMapping(value = "/handMatchCar")
    public ApiResult<Boolean> handMatchCar(@CurrentUser LoginInfo user,@RequestBody OrderApproveHandMatchCarReqVO vo){
        Object partnerVO = (Object) user.getPartner();
        if(partnerVO != null){
            //
            //表示当前用户是主机厂
            return ResponseUtil.fail(401,"当前用户不是主机厂用户，请使用主机厂用户登录！");
        }

        boolean isSuccess = orderOemManagerDubboService.handMatchCar(vo);
        return ResponseUtil.ok(isSuccess);
    }

    @ApiOperation(value = "手动配车VIP")
    @PostMapping(value = "/handMatchCarVip")
    public ApiResult<Boolean> handMatchCarVip(@CurrentUser LoginInfo user,@RequestBody OrderApproveHandMatchCarReqVO vo){
        Object partnerVO = (Object) user.getPartner();
        if(partnerVO != null){
            //
            //表示当前用户是主机厂
            return ResponseUtil.fail(401,"当前用户不是主机厂用户，请使用主机厂用户登录！");
        }

        boolean isSuccess = orderOemManagerDubboService.handMatchCarVip(vo);
        return ResponseUtil.ok(isSuccess);
    }

    @ApiOperation(value = "取消配车")
    @PostMapping(value = "/cancelMatchCar")
    public ApiResult<Boolean> cancelMatchCar(@CurrentUser LoginInfo user,@RequestBody OrderApproveAutoMatchCarReqVO vo){
        Object partnerVO = (Object) user.getPartner();
        if(partnerVO != null){
            //
            //表示当前用户是主机厂
            return ResponseUtil.fail(401,"当前用户不是主机厂用户，请使用主机厂用户登录！");
        }

        boolean isSuccess = orderOemManagerDubboService.cancelMatchCar(vo);
        return ResponseUtil.ok(isSuccess);
    }

    @ApiOperation(value = "配车更换")
    @PostMapping(value = "/chooseMatchCar")
    public ApiResult<Boolean> chooseMatchCar(@CurrentUser LoginInfo user,@RequestBody OrderApproveHandMatchCarReqVO vo){
        Object partnerVO = (Object) user.getPartner();
        if(partnerVO != null){
            //
            //表示当前用户是主机厂
            return ResponseUtil.fail(401,"当前用户不是主机厂用户，请使用主机厂用户登录！");
        }

        boolean isSuccess = orderOemManagerDubboService.chooseMatchCar(vo);
        return ResponseUtil.ok(isSuccess);
    }

    @ApiOperation(value = "订单配车")
    @GetMapping(value = "/queryOrderApproveMatchCarForPage")
    public ApiResult<OrderVehicleManagerDetailsRespVO> queryOrderApproveMatchCarForPage(@CurrentUser LoginInfo user,OrderVehicleManagerDetailsReqVO vo, int pageNum, int pageSize) {
        Object partnerVO = (Object) user.getPartner();
        if(partnerVO != null){
            //
            //表示当前用户是主机厂
            return ResponseUtil.fail(401,"当前用户不是主机厂用户，请使用主机厂用户登录！");
        }

        PageInfo<OrderVehicleManagerDetailsRespVO> pageInfo = orderOemManagerDubboService.queryOrderApproveMatchCarForPage(vo,pageNum,pageSize);
        return ResponseUtil.ok(pageInfo);
    }

    @ApiOperation(value = "大客户订单配车")
    @GetMapping(value = "/queryOrderApproveMatchCarForPageVip")
    public ApiResult<OrderVehicleManagerDetailsRespVO> queryOrderApproveMatchCarForPageVip(@CurrentUser LoginInfo user,OrderVehicleManagerDetailsReqVO vo, int pageNum, int pageSize) {
        Object partnerVO = (Object) user.getPartner();
        if(partnerVO != null){
            vo.setPartnerCode(user.getPartnerCode());
            vo.setSubmitType(0);
        }else{
            vo.setSubmitType(1);
        }

        PageInfo<OrderVehicleManagerDetailsRespVO> pageInfo = orderOemManagerDubboService.queryOrderApproveMatchCarForPage(vo,pageNum,pageSize);
        return ResponseUtil.ok(pageInfo);
    }

    @ApiOperation(value = "订单审核")
    @GetMapping(value = "/queryOrderApproveCheckForPage")
    public ApiResult<OrderVehicleManagerDetailsRespVO> queryOrderApproveCheckForPage(@CurrentUser LoginInfo user,OrderVehicleManagerDetailsReqVO vo, int pageNum, int pageSize) {
        Object partnerVO = (Object) user.getPartner();
        if(partnerVO != null){
            //
            //表示当前用户是主机厂
            return ResponseUtil.fail(401,"当前用户不是主机厂用户，请使用主机厂用户登录！");
        }

        PageInfo<OrderVehicleManagerDetailsRespVO> pageInfo = orderOemManagerDubboService.queryOrderApproveCheckForPage(vo,pageNum,pageSize);
        return ResponseUtil.ok(pageInfo);
    }

    @ApiOperation(value = "财务审批")
    @GetMapping(value = "/queryOrderApproveCheckExpienceForPage")
    public ApiResult<OrderVehicleManagerDetailsRespVO> queryOrderApproveCheckExpienceForPage(@CurrentUser LoginInfo user,OrderVehicleManagerDetailsReqVO vo, int pageNum, int pageSize) {
        Object partnerVO = (Object) user.getPartner();
        if(partnerVO != null){
            //
            //表示当前用户是主机厂
            return ResponseUtil.fail(401,"当前用户不是主机厂用户，请使用主机厂用户登录！");
        }

        PageInfo<OrderVehicleManagerDetailsRespVO> pageInfo = orderOemManagerDubboService.queryOrderApproveCheckExpienceForPage(vo,pageNum,pageSize);
        return ResponseUtil.ok(pageInfo);
    }

    @ApiOperation(value = "订单审核")
    @GetMapping(value = "/queryOrderApproveCheckForPageVip")
    public ApiResult<OrderVehicleManagerDetailsRespVO> queryOrderApproveCheckForPageVip(@CurrentUser LoginInfo user,OrderVehicleManagerDetailsReqVO vo, int pageNum, int pageSize) {
        Object partnerVO = (Object) user.getPartner();

        PageInfo<OrderVehicleManagerDetailsRespVO> pageInfo = orderOemManagerDubboService.queryOrderApproveCheckForPageVip(vo,pageNum,pageSize);
        return ResponseUtil.ok(pageInfo);
    }

    @ApiOperation(value = "订单审核,订单导出")
    @GetMapping(value = "/queryOrderApproveCheckForDownload")
    public ApiResult<OrderVehicleManagerDetailsRespVO> queryOrderApproveCheckForDownload(@CurrentUser LoginInfo user,OrderVehicleManagerDetailsReqVO vo){
        Object partnerVO = (Object) user.getPartner();
        if(partnerVO != null){
            //
            //表示当前用户是主机厂
            return ResponseUtil.fail(401,"当前用户不是主机厂用户，请使用主机厂用户登录！");
        }

        PageInfo<OrderVehicleManagerDetailsRespVO> pageInfo = orderOemManagerDubboService.queryOrderApproveCheckForDownload(vo);
        return ResponseUtil.ok(pageInfo);
    }

    @ApiOperation(value = "财务审批导出")
    @GetMapping(value = "/queryOrderApproveCheckExpienceForDownload")
    public ApiResult<OrderVehicleManagerDetailsRespVO> queryOrderApproveCheckExpienceForDownload(@CurrentUser LoginInfo user,OrderVehicleManagerDetailsReqVO vo) {
        Object partnerVO = (Object) user.getPartner();
        if(partnerVO != null){
            //
            //表示当前用户是主机厂
            return ResponseUtil.fail(401,"当前用户不是主机厂用户，请使用主机厂用户登录！");
        }

        List<OrderVehicleManagerDetailsRespVO> pageInfo = orderOemManagerDubboService.queryOrderApproveCheckExpienceForDownload(vo);
        return ResponseUtil.ok(pageInfo);
    }

    @ApiOperation(value = "订单优先级设置")
    @GetMapping(value = "/queryOrderApprovePrioritySettingForPage")
    public ApiResult<OrderVehicleManagerDetailsRespVO> queryOrderApprovePrioritySettingForPage(@CurrentUser LoginInfo user,OrderVehicleManagerDetailsReqVO vo, int pageNum, int pageSize) {
        Object partnerVO = (Object) user.getPartner();
        if(partnerVO != null){
            //
            //表示当前用户是主机厂
            return ResponseUtil.fail(401,"当前用户不是主机厂用户，请使用主机厂用户登录！");
        }

        PageInfo<OrderVehicleManagerDetailsRespVO> pageInfo = orderOemManagerDubboService.queryOrderApprovePrioritySettingForPage(vo,pageNum,pageSize);
        return ResponseUtil.ok(pageInfo);
    }

    @ApiOperation(value = "总部代创建")
    @PostMapping(value = "/generationCreate")
    public ApiResult<Boolean> generationCreate(@RequestBody OrderOemSaveReqVO vo, @CurrentUser LoginInfo user){
        Object partnerVO = (Object) user.getPartner();
        if(partnerVO != null){
            //
            //表示当前用户是主机厂
            return ResponseUtil.fail(401,"当前用户不是主机厂用户，请使用主机厂用户登录！");
        }

        vo.setCreateBy(user.getUserCode());
        vo.setUserCode(user.getUserCode());
        boolean isSuccess = orderOemManagerDubboService.savePmsOrderOem(vo,user);
        return ResponseUtil.ok(isSuccess);
    }

    /**
     * 主机厂端代创订单时价格试算
     * @param user
     * @param vo
     * @return
     */
    @ApiOperation(value = "价格试算")
    @PostMapping(value = "/priceTryCompute")
    public ApiResult<PriceTryComputeRespVO> priceTryCompute(@CurrentUser LoginInfo user,@RequestBody  OrderOemSaveReqVO vo){
        Object partnerVO = (Object) user.getPartner();
        if(partnerVO != null){
            //
            //表示当前用户是渠道商
            return ResponseUtil.fail(401,"当前用户不是主机厂用户，请使用主机厂用户登录！");
        }
        PriceTryComputeRespVO tryResult = orderOemManagerDubboService.priceTryCompute(vo);
        return ResponseUtil.ok(tryResult);
    }

    @ApiOperation(value = "价格试算Vip")
    @PostMapping(value = "/priceTryComputeVip")
    public ApiResult<PriceTryComputeRespVO> priceTryComputeVip(@CurrentUser LoginInfo user,@RequestBody  OrderOemSaveReqVO vo){
        PriceTryComputeRespVO tryResult = orderOemManagerDubboService.priceTryCompute(vo);
        return ResponseUtil.ok(tryResult);
    }

    @ApiOperation(value = "取消订单审核状态修改")
    @PostMapping(value = "/updateOrderCancelReasonForCheckStatus")
    public ApiResult<Boolean> updateOrderCancelReasonForCheckStatus(@CurrentUser LoginInfo user,@RequestBody  OrderCancelReasonReqVO vo){
        Object partnerVO = (Object) user.getPartner();
        if(partnerVO != null){
            //
            //表示当前用户是主机厂
            return ResponseUtil.fail(401,"当前用户不是主机厂用户，请使用主机厂用户登录！");
        }

        vo.setUserCode(user.getUserCode());

        boolean isSuccess  = orderOemManagerDubboService.updateOrderCancelReasonForCheckStatus(vo);
        return ResponseUtil.ok(isSuccess);
    }
    @ApiOperation(value = "订单修改审核状态修改")
    @PostMapping(value = "/updateOrderModifyApplyForCheckStatus")
    public ApiResult<Boolean> updateOrderModifyApplyForCheckStatus(@CurrentUser LoginInfo user,@RequestBody  OrderModifyApplyReqVO vo){
        Object partnerVO = (Object) user.getPartner();
        if(partnerVO != null){
            //
            //表示当前用户是主机厂
            return ResponseUtil.fail(401,"当前用户不是主机厂用户，请使用主机厂用户登录！");
        }

        vo.setUserCode(user.getUserCode());
        boolean isSuccess = orderOemManagerDubboService.updateOrderModifyApplyForCheckStatus(vo);
        return ResponseUtil.ok(isSuccess);
    }

    @ApiOperation(value = "导出没有配车的订单")
    @GetMapping(value = "/queryNoMatchCarOrderForDownload")
    public ApiResult<NoMatchCarOrderForDownloadRespVO> queryNoMatchCarOrderForDownload(@CurrentUser LoginInfo user){
        Object partnerVO = (Object) user.getPartner();
        if(partnerVO != null){
            //
            //表示当前用户是主机厂
            return ResponseUtil.fail(401,"当前用户不是主机厂用户，请使用主机厂用户登录！");
        }

        List<NoMatchCarOrderForDownloadRespVO> list = orderOemManagerDubboService.queryNoMatchCarOrderForDownload();
        return ResponseUtil.ok(list);
    }


}
